﻿@{ 
    Layout = null;

} 
<div class="modal-dialog" role="document">
    <div class="modal-content" style="width:800px;">
        <div class="modal-body">
            <h3>
                <strong>导入</strong>
            </h3>
            <hr />
            <!--html代码区域-->
            <form id="form" name="form" role="form" novalidate class="form-validation">
                
                <div class="row p-xxs">
                    <div class="form-group form-md-line-input form-md-floating-label  ">
                        <label class="control-label pull-left">数据文件</label>
                        <div class="col-md-10">
                            <input type="file" id="excelFile" accept=".xls, .xlsx" />
                        </div>
                    </div>
                </div>
            </form>
             
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" id="id_submit">提交</button>
        </div>
    </div>
</div>
<script src="~/Scripts/extend/jquery.form.js"></script>
<script type="text/javascript">
    
    var modal = $("#@Request["ModalID"]");
    $(function () {

    });
    $("#id_submit").on("click",
        function () {
            var formData = new FormData();
            var name = $("#excelFile").val();
            formData.append("file", $("#excelFile")[0].files[0]);
            formData.append("name", name); 
            $.ajax({
                    url: "/Guide/ImportFromExcel",
                    type: "post",
                    data: formData,
                    processData: false,
                    contentType: false
                })
                .done(function (data) {
                    if (data.code > 0) {
                        alert(data.msg);
                        //toastr.success(data.msg);
                        modal.modal('hide');
                    } else {
                        toastr.warning(data.msg);
                        console.log(data.msg);
                    }
                })
                .fail(function (data) {
                    toastr.warning(data.msg);
                    console.log(data);
                }); 
        });
     
</script>
